import 'package:elevator_app/model/bean/community_bean.dart';

import '../apis/resquest/http.dart';
import '../model/bean/login_info.dart';

class Base {
  /// 登录
  /// * [data] Map|请求参数|必填
  static login(Map<String, dynamic> data) async {
    const url = '/elevator-maintenance-app/user/login';
    try {
      HttpResponse _r = await Http.getInstance().post(url, params: data);
      return LoginInfo.fromJson(_r.data);
    } catch (e) {
      print("登录时候出现的错误：${e}");
    }
  }

  /// 登出
  static logout() async {
    const url = '/elevator-maintenance-app/user/logout';
    try {
      HttpResponse _r = await Http.getInstance().post(url);
      return _r.data;
    } catch (e) {
      throw e;
    }
  }

  /// 上传文件
  /// * [data] Map|请求参数|必填
  static uploadfile(dynamic data) async {
    const url = '/elevator-maintenance-app/file/upload';
    try {
      HttpResponse _r = await Http.getInstance().uploadfile(url, params: data);
      return _r.data;
    } catch (e) {
      throw e;
    }
  }

  /// 查询小区
  static queryCommunity() async {
    const url = '/elevator-maintenance-app/village/getVillageByMaintainer';
    try {
      HttpResponse _r = await Http.getInstance().get(url);
      return CommunityListBean.fromJson(_r.data);
    } catch (e) {}
  }

  /// 获取app版本信息
  static queryAppEdition() async {
    const url = '/elevator-maintenance-app/appEditionQuery/getAppEdition';
    try {
      HttpResponse _r = await Http.getInstance().get(url);
      return _r.data;
    } catch (e) {}
  }
}
